import http from './axios'
//定义方法    统一管理请求



//商品列表 + 搜索
function getGoodsList(name='',pageNum=1,pageSize=10,categoryId='') {
    return http.post('/e-mall-api/api/shop/shopGoods/open/list?name='+name+'&pageNum='+pageNum+'&pageSize='+pageSize+'&categoryId='+categoryId)
}
export {getGoodsList}
//首页轮播图
export function carousel() {
    return http.get('/e-mall-api/api/shop/shopGoods/open/banner/list')
}

//商品详情
function getGoodsMsg(id){
    return http.get('/e-mall-api/api/shop/shopGoods/open/detail/'+id)
}
export {getGoodsMsg}

//首页商品分类
export function goodsClassify() {
    return http.post('/e-mall-api/api/shop/shopCategory/open/list')
}
//每日推荐
export function Recommendation(pageNum = 1,pageSize = 10){
    return http.post('/e-mall-api/api/shop/shopGoods/open/recommend/list?pageSize='+pageSize+"&pageNum="+pageNum)
}

//商品列表
export function ProductList(){
    return http.post('/e-mall-api/api/shop/shopGoods/open/list')
}

//分类列表
export function shopCategory(){
    return http.post('/e-mall-api/api/shop/shopCategory/open/list')
}

//热门商品
export function hotGoods(pageNum = 1,pageSize = 10){
    return http.post('/e-mall-api/api/shop/shopGoods/open/hot/list?pageSize='+pageSize+"&pageNum="+pageNum)
}




//账号密码登录
export function AccounsSign (name, password) {
    let from = new URLSearchParams()
    from.append("username" , name)
    from.append("password" , password)
    from.append("rememberMe" , true)
    return http.post('/e-mall-api/api/login', from)
}
//注册
export function registerSign(name,password ,phone,code,user,sex) {
    let from = new URLSearchParams()
    from.append("loginName", name)
    from.append("password" , password)
    from.append("phonenumber" , phone)
    from.append("code" , code)
    from.append("userName" , user)
    from.append("sex" , sex)
    return http.post('/e-mall-api/api/registry', from)
}
//发送验证码
export function PhoneSignApi(mobile){
    return http.get('/e-mall-api/api/short-message/vcode/'+mobile)
}

//获取个人信息
function getPersonMsg(){
    return http.get('/e-mall-api/api/login-user/info')
}
export {getPersonMsg}

//获取订单信息
function getMyGoods(){
    return http.post('/e-mall-api/api/shop/shopOrder/site/login-user/list')
}
export {getMyGoods}

//添加到购物车
function shopCarAdd(goodsId,num){
    let format = new URLSearchParams()
    format.append('goodsId',goodsId)
    format.append('num',num)
    return http.post('/e-mall-api/api/shop/shopShoppingCart/site/add',format)
}
export {shopCarAdd}

//获取购物车列表
function getShopCarList(){
    return http.get('/e-mall-api/api/shop/shopShoppingCart/site/login-user/list')
}
export {getShopCarList}

//忘记密码
export function Forgotpass(loginName,password,phonenumber,code){
    let from = new URLSearchParams()
    from.append("loginName", loginName)
    from.append("password", password)
    from.append("phonenumber", phonenumber)
    from.append("code", code)
    return http.post('/e-mall-api/api/password/forget',from)
}
//修改个人信息
export function PhoneSignApiddd(userName,phonenumber,sex){
    let from = new URLSearchParams()
    from.append("userName", userName)
    from.append("phonenumber", phonenumber)
    from.append("sex", sex)
    return http.post('/e-mall-api/api/system/user/profile/update',from)
}
//修改头像
export function uploadImgApi(file){
    let from = new FormData()
    from.append("avatarfile", file)
    return http.post('/e-mall-api/api/system/user/profile/update/avatar/nos',from)
}
//查看个人信息
export function personalInformation(){
    return http.get('/e-mall-api/api/login-user/info')
}
//退出登录
export function Signout(){
    return http.get('/e-mall-api/api/logout')
}


//购物车修改个数
function changeShopCarNum(cartId,num){
    return http.get(`/e-mall-api/api/shop/shopShoppingCart/site/change/num/${cartId}/${num}`)
}
export {changeShopCarNum}

//其他接口1---搞笑段子
function play1(){
    return http.get(' https://www.mxnzp.com/api/jokes/list/random?app_id=xualomrngsqasqqb&app_secret=ZWtBWXY1Wk5yeU02dVhVWktqWnpYdz09')
}
export {play1}
//其他接口2---心灵鸡汤(还在审核中)
function play2(){
    return http.get('https://apis.juhe.cn/fapig/soup/query?key=')
}
export {play2}



// 获取购物车列表，未登录则返回403
export function getBuyCarList(){
    return http.get('/e-mall-api/api/shop/shopShoppingCart/site/login-user/list')
}

// 删除购物车中的商品
export function deleteShops(ids){
    let formUrl = new URLSearchParams()
    formUrl.append('ids',ids)
    return http.post('/e-mall-api/api/shop/shopShoppingCart/site/remove',formUrl)
}
//第三方接口文字转图片
export  function textTurnImg(text){
        return http.get('https://api.vvhan.com/api/qr?text='+text)
}
//豆瓣前10排行
export  function film(){
        return http.get('https://api.vvhan.com/api/douban')
}
// 确认订单
export function makesureOrder(goodsList,address,mobile,total){
    return http.post(`/e-mall-api/api/shop/shopOrder/site/add?goodsList=${goodsList}&address=${address}&mobile=${mobile}&total=${total}`)
}
export function getVideos(page=0){
    return http.get(`/video?page=${page}&size=10`)
}

// //文章生成器
// export function writeArticle(msg){
//     return http.get('/robot-api/api/dog.php?msg='+msg+'&num=257')
// }
//青客云机器人
export function robot(msg){
    return http.get('/robot-api/api/liaotian.php?msg='+msg)
}
//答案之书
export function book(){
    return http.get('/robot-api/daan.php')
}
// //短视频接口
// export function video2(){
//     return http.get('/api/vs.php')
// }


